package com.shujia.zookeeper;

import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooKeeper;

import java.io.IOException;

public class Code05DeleteNode {
    public static void main(String[] args) throws IOException, InterruptedException, KeeperException {
        ZooKeeper zooKeeper = new ZooKeeper("master:2181",
                15 * 1000,
                new Watcher() {
                    @Override
                    public void process(WatchedEvent event) {
                        System.out.println("process函数执行了...");
                    }
                }
        );

//        String path = "/api/node1/node11";
        String path = "/api/node2";
        zooKeeper.delete(path,-1); // 最新版本选择-1  delete函数要求不为空

        // 作业2：自定义一个deleteAll函数，实现非空的节点删除功能

        zooKeeper.close();
    }
}
